home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Scripts / CompareRevisions < prev    next >
Encoding:
Text File  |  1997-12-04  |  3.9 KB  |  156 lines  |  [TEXT/MPS ]

  1. #
  2. #    CompareRevisions - Compare the revision in the named file with another revision
  3. #                    of the same file.
  4. #
  5. #    Usage:    CompareRevisions file
  6. #
  7. #    CompareRevisions compares the revision of the named file with another revision
  8. #    of the same file. If they don't match it brings them both up on the screen and
  9. #    puts them side by side.  A menu is appended to the menu bar to go through
  10. #    the changes.  When all the changes have been shown, the revision windows are
  11. #    restored and closed.
  12. #
  13. #    The differences are shown from bottom to top so that if any changes are made
  14. #    in the files, the line offsets are not messed up.
  15. #
  16. #    To add CompareRevisions to a menu, execute the following command:
  17. #
  18. #        AddMenu Project 'CompareRevisions' 'CompareRevisions "{Active}" ∑∑ "{WorkSheet}"'
  19. #
  20. #    This script creates three temporary files which are deleted on exit or abort.
  21. #    {TempFolder}Compare_File, {TempFolder}Compare_State and file,<rev>,
  22. #
  23. #
  24. #    NOTE:
  25. #    1. CompareRevisions calls the script CompareFiles.
  26. #
  27. #    © Apple Computer, Inc. 1988 - 1993, 1997
  28. #    All rights reserved.
  29.  
  30. Set Exit 0
  31. Set error 0
  32. Begin
  33.  
  34.     #    Check parameters.
  35.     
  36.     If {#} ≠ 1
  37.         Echo "### Usage - {0} file"
  38.         Exit 0
  39.     End    >> Dev:StdErr
  40.     
  41.     #    Make sure the file exists
  42.  
  43.     If "" == "`Exists -f "{1}"`"
  44.         Echo "### {0} - File ∂"{1}∂" not found"
  45.         Exit 4
  46.     End
  47.         
  48.     #    Break apart the pathname.
  49.     
  50.     Set f "{1}"
  51.     If "{f}" =~ /(≈)®1:(≈)®2/
  52.         Set dir "{®1}:"
  53.         Set f "{®2}"
  54.     Else
  55.         Set dir `directory`
  56.         If "{dir}" =~ /(≈)®1:/
  57.             Set dir "{®1}:"
  58.         End
  59.     End
  60.     
  61.     Set path "{dir}{f}"
  62.  
  63.     #    See if the file belongs to a project.
  64.     #    Then find the name of the parent project.
  65.     
  66.     (Set info "`ProjectInfo "{path}"`" || Set error 1)
  67.     (Evaluate "{info}" =~ /[¬,]+,([¬ ∂t+*∂']+)®4([+*]«0,1»)®1[∂']* ≈/
  68.     Evaluate "{info}" =~ /≈Project: (≈∫)®2 +Checked out≈/ ) >dev:null
  69.     If {error} ≠ 0 || "{info}" == ""
  70.         Alert "∂"{path}∂" doesn’t belong to a project."
  71.         Exit 0 
  72.     End
  73.     Set rev1 "{®4}"
  74.  
  75.     #    At this point:
  76.     #        {®1}    =>    '', '+', or '*'
  77.     #        {®2}     =>    project path
  78.     #        {path}     =>    file pathname
  79.     #        {rev1}     =>    revision
  80.     #        {dir}     =>    file directory path
  81.     #        {f}     =>    file leaf name
  82.     #
  83.     #    Is the right project mounted?
  84.     
  85.     (Set revList "`ProjectInfo -s -project "{®2}" "{f}"`") ≥dev:null
  86.     If "{revlist}" == ""
  87.         Alert "Project ∂"{®2}∂" is not mounted."
  88.  
  89.         Exit 0 
  90.     End
  91.     
  92.     #   Remove checked out ('+') revisions from the revision list.
  93.  
  94.     Loop
  95.         If "`Evaluate " {revlist}" =~ /(≈)®7 (∂')«0,1»{f},[¬+]+∂+(∂')«0,1»(≈)®8/`"
  96.             Set revlist "{®7}{®8}"
  97.         Else 
  98.             Break
  99.         End
  100.     End
  101.     
  102.     #   Remove the current revision from the revision list.
  103.  
  104.     If  ".{®1}" !~ /.[+*]/ && "`Evaluate " {revlist}" =~ /(≈[¬'])®7[∂']«0,1»{f},{rev1}[∂']«0,1»(≈)®8/`"
  105.         Set revlist "{®7}{®8}"
  106.     End > dev:null
  107.     
  108.     If "{revlist}" =~ / */
  109.         Alert "No revisions to compare against."
  110.         Exit 4                # we're done if the rev list is null
  111.     End
  112.  
  113.     #    Request the number of the revision to be compared.
  114.  
  115.     (Set rev2 "`GetListItem -q -s -r 8 -m "Compare ∂"{f},{rev1}{®1}∂" with:" -d {revList} ∂
  116.         || Set error {Status}`")
  117.  
  118.     If {error} == 0
  119.         
  120.         (Evaluate "{rev2}" =~ /≈,(≈)®7/ ) >dev:null
  121.         Set rev2 "{®7}"
  122.  
  123.     #    Rename the active window so we can checkout a read-only copy of the
  124.     #    revision we want to compare against.  We'll have to change the name back.
  125.         
  126.     #    Find a temporary directory where I can checkout the file
  127.         Set coDir "{TempFolder}CompareRevisions.Dir:"
  128.         Delete -i -y "{coDir}"
  129.         NewFolder "{coDir}"
  130.                 
  131.         (Checkout "{f},{rev2}" -d "{coDir}" -project "{®2}" || Set error {Status})
  132.         If {error} ≠ 0
  133.             Alert "∂"{f},{rev2}∂" can’t be checked out [{error}]."
  134.             Rename "{path},{rev1}{®1}" "{path}"
  135.             Delete -i -y "{coDir}"
  136.             Exit 0 
  137.         End
  138.         
  139.         Move "{coDir}{f}" "{path},{rev2}"
  140.         Delete -i -y "{coDir}"
  141.  
  142.     #    Compare the two files and then clean up.
  143.     
  144.         CompareFiles "{path}" "{path},{rev2}" ∑ dev:null
  145.         Set MyStatus {Status}
  146.         If {MyStatus} == 2
  147.             Echo Delete ∂""{path},{rev2}"∂" >> "{TempFolder}Compare_State"
  148.         Else If {MyStatus} == 3
  149.             Delete "{path},{rev2}"
  150.         Else If {MyStatus} == 0
  151.             Alert "Revisions match."
  152.             Delete "{path},{rev2}"
  153.         End
  154.     End
  155. End 
  156.